//
//  PersonShowView.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/8/29.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "PersonShowView.h"

@interface PersonShowView ()

@property (strong, nonatomic) UIImageView *bgImg;
@property (strong, nonatomic) UIImageView *trousersImg;
@property (strong, nonatomic) UIImageView *shoesImg;
@property (strong, nonatomic) UIImageView *clothesImg;
@property (strong, nonatomic) UIImageView *baseModelView;
@property (strong, nonatomic) UIImageView *earringsImg;

@end

@implementation PersonShowView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.bgImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH(self), HEIGHT(self))];
        self.bgImg.clipsToBounds = YES;
        self.bgImg.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:self.bgImg];
    }
    return self;
}

- (void)setSex:(NSString *)sex {
    _sex = sex;
}

- (void)setAge:(NSString *)age {
    _age = age;
    if ([self.sex isEqualToString:@"男"]) {
        if ([self.age isEqualToString:@"青年"] || [self.age isEqualToString:@"壮年"] || [self.age isEqualToString:@"老年"]) {
            [self setBaseMan];
        }else if ([self.age isEqualToString:@"儿童"]) {
            [self setBaseBoy];
        }
    }else {
        if ([self.age isEqualToString:@"青年"] || [self.age isEqualToString:@"壮年"] || [self.age isEqualToString:@"老年"]) {
            [self setBaseWoman];
        }else if ([self.age isEqualToString:@"儿童"]) {
            [self setBaseGirl];
        }
    }
}

- (void)setBackGroundWithImage:(NSString *)imageUrl {
    [self.bgImg sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil options:SDWebImageRetryFailed];
}

- (void)setHeadWithImage:(NSString *)imageUrl {
    [self.baseModelView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        if ([self.sex isEqualToString:@"男"]) {
            if ([self.age isEqualToString:@"青年"] || [self.age isEqualToString:@"壮年"] || [self.age isEqualToString:@"老年"]) {
                self.baseModelView.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(141) - CGImageGetHeight(image.CGImage), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
            }else if ([self.age isEqualToString:@"儿童"]) {
                self.baseModelView.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(243) - CGImageGetHeight(image.CGImage), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
            }
        }else {
            if ([self.age isEqualToString:@"青年"] || [self.age isEqualToString:@"壮年"] || [self.age isEqualToString:@"老年"]) {
                self.baseModelView.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(75), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
            }else if ([self.age isEqualToString:@"儿童"]) {
                self.baseModelView.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(242) - CGImageGetHeight(image.CGImage), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
            }
        }
    }];
}

- (void)setClothesWithImage:(NSString *)imageUrl {
    [self.clothesImg sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        if ([self.sex isEqualToString:@"男"]) {
            if ([self.age isEqualToString:@"青年"] || [self.age isEqualToString:@"壮年"] || [self.age isEqualToString:@"老年"]) {
                self.clothesImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(130), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
            }else if ([self.age isEqualToString:@"儿童"]) {
                self.clothesImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(240), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
            }
            
        }else {
            if ([self.age isEqualToString:@"青年"] || [self.age isEqualToString:@"壮年"] || [self.age isEqualToString:@"老年"]) {
                self.clothesImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(130), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
            }else if ([self.age isEqualToString:@"儿童"]) {
                self.clothesImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(240), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
            }
            
        }
    }];
}

- (void)setEarringsWithImage:(NSString *)imageUrl {
    [self.earringsImg sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        if ([self.sex isEqualToString:@"男"]) {
            self.earringsImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(80), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
        }else {
            self.earringsImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(105), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
        }
    }];
}

- (void)setTrousersWithImage:(NSString *)imageUrl {
    [self.trousersImg sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        if ([self.sex isEqualToString:@"男"]) {
            if ([self.age isEqualToString:@"青年"] || [self.age isEqualToString:@"壮年"] || [self.age isEqualToString:@"老年"]) {
                self.trousersImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(220), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
            }else if ([self.age isEqualToString:@"儿童"]) {
                self.trousersImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(305), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
            }
            
        }else {
            if ([self.age isEqualToString:@"青年"] || [self.age isEqualToString:@"壮年"] || [self.age isEqualToString:@"老年"]) {
                self.trousersImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(208), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
            }else if ([self.age isEqualToString:@"儿童"]) {
                self.trousersImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2, ScreenX375(302), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
            }
            
        }
    }];
}

- (void)setShoesWithImage:(NSString *)imageUrl {
    [self.shoesImg sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        if ([self.sex isEqualToString:@"男"]) {
            self.shoesImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2 + ScreenX375(6), CGRectGetMaxY(self.trousersImg.frame) - CGImageGetHeight(image.CGImage) + ScreenX375(9), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
        }else {
            self.shoesImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(image.CGImage)) / 2 - ScreenX375(27), CGRectGetMaxY(self.trousersImg.frame) - CGImageGetHeight(image.CGImage) + ScreenX375(26), CGImageGetWidth(image.CGImage), CGImageGetHeight(image.CGImage));
        }
    }];
}

- (void)setBaseMan {
    UIImage *head = ImageWithName(@"男青年头部2");
    UIImage *clothes = ImageWithName(@"男上身");
    UIImage *trousers = ImageWithName(@"男下身");
    UIImage *shoes = ImageWithName(@"男鞋");
    UIImage *earrings = ImageWithName(@"男耳环");
    self.trousersImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(trousers.CGImage)) / 2, ScreenX375(230), CGImageGetWidth(trousers.CGImage), CGImageGetHeight(trousers.CGImage));
//    self.trousersImg.image = trousers;
    
    self.shoesImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(shoes.CGImage)) / 2 + ScreenX375(6), CGRectGetMaxY(self.trousersImg.frame) - CGImageGetHeight(shoes.CGImage) + ScreenX375(9), CGImageGetWidth(shoes.CGImage), CGImageGetHeight(shoes.CGImage));
//    self.shoesImg.image = shoes;
    
    self.clothesImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(clothes.CGImage)) / 2, ScreenX375(130), CGImageGetWidth(clothes.CGImage), CGImageGetHeight(clothes.CGImage));
//    self.clothesImg.image = clothes;
    
    self.baseModelView.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(head.CGImage)) / 2, ScreenX375(131) - CGImageGetHeight(head.CGImage), CGImageGetWidth(head.CGImage), CGImageGetHeight(head.CGImage));
//    self.baseModelView.image = head;
    
    self.earringsImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(earrings.CGImage)) / 2, ScreenX375(100), CGImageGetWidth(earrings.CGImage), CGImageGetHeight(earrings.CGImage));
//    self.earringsImg.image = earrings;
}

- (void)setBaseWoman {
    UIImage *head = ImageWithName(@"女青年头部2");
    UIImage *clothes = ImageWithName(@"女上身");
    UIImage *trousers = ImageWithName(@"女下身");
    UIImage *shoes = ImageWithName(@"女鞋");
    UIImage *earrings = ImageWithName(@"女耳环");
    self.trousersImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(trousers.CGImage)) / 2, ScreenX375(208), CGImageGetWidth(trousers.CGImage), CGImageGetHeight(trousers.CGImage));
//    self.trousersImg.image = trousers;
    
    self.shoesImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(shoes.CGImage)) / 2 - ScreenX375(27), CGRectGetMaxY(self.trousersImg.frame) - CGImageGetHeight(shoes.CGImage) + ScreenX375(26), CGImageGetWidth(shoes.CGImage), CGImageGetHeight(shoes.CGImage));
//    self.shoesImg.image = shoes;
    
    self.clothesImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(clothes.CGImage)) / 2, ScreenX375(130), CGImageGetWidth(clothes.CGImage), CGImageGetHeight(clothes.CGImage));
//    self.clothesImg.image = clothes;
    
    self.baseModelView.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(head.CGImage)) / 2, ScreenX375(75), CGImageGetWidth(head.CGImage), CGImageGetHeight(head.CGImage));
//    self.baseModelView.image = head;
    
    self.earringsImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(earrings.CGImage)) / 2, ScreenX375(125), CGImageGetWidth(earrings.CGImage), CGImageGetHeight(earrings.CGImage));
//    self.earringsImg.image = earrings;
}

- (void)setBaseGirl {
    UIImage *head = ImageWithName(@"女儿童头部2");
    UIImage *clothes = ImageWithName(@"女儿童上身");
    UIImage *trousers = ImageWithName(@"女儿童下身");
    self.trousersImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(trousers.CGImage)) / 2, ScreenX375(302), CGImageGetWidth(trousers.CGImage), CGImageGetHeight(trousers.CGImage));
//    self.trousersImg.image = trousers;
    
    self.clothesImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(clothes.CGImage)) / 2, ScreenX375(240), CGImageGetWidth(clothes.CGImage), CGImageGetHeight(clothes.CGImage));
//    self.clothesImg.image = clothes;
    
    self.baseModelView.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(head.CGImage)) / 2, ScreenX375(242) - CGImageGetHeight(head.CGImage), CGImageGetWidth(head.CGImage), CGImageGetHeight(head.CGImage));
//    self.baseModelView.image = head;
}

- (void)setBaseBoy {
    UIImage *head = ImageWithName(@"男儿童头部1");
    UIImage *clothes = ImageWithName(@"男儿童上半身");
    UIImage *trousers = ImageWithName(@"男儿童下半身");
    self.trousersImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(trousers.CGImage)) / 2, ScreenX375(305), CGImageGetWidth(trousers.CGImage), CGImageGetHeight(trousers.CGImage));
//    self.trousersImg.image = trousers;
    
    self.clothesImg.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(clothes.CGImage)) / 2, ScreenX375(240), CGImageGetWidth(clothes.CGImage), CGImageGetHeight(clothes.CGImage));
//    self.clothesImg.image = clothes;
    
    self.baseModelView.frame = CGRectMake((WIDTH(self) - CGImageGetWidth(head.CGImage)) / 2, ScreenX375(243) - CGImageGetHeight(head.CGImage), CGImageGetWidth(head.CGImage), CGImageGetHeight(head.CGImage));
//    self.baseModelView.image = head;
}

- (UIImageView *)baseModelView {
    if (!_baseModelView) {
        UIImageView *imageView = [[UIImageView alloc] init];
        [self addSubview:imageView];
        _baseModelView = imageView;
    }
    return _baseModelView;
}

- (UIImageView *)clothesImg {
    if (!_clothesImg) {
        UIImageView *imageView = [[UIImageView alloc] init];
        [self addSubview:imageView];
        _clothesImg = imageView;
    }
    return _clothesImg;
}

- (UIImageView *)earringsImg {
    if (!_earringsImg) {
        UIImageView *imageView = [[UIImageView alloc] init];
        [self addSubview:imageView];
        _earringsImg = imageView;
    }
    return _earringsImg;
}

- (UIImageView *)trousersImg {
    if (!_trousersImg) {
        UIImageView *imageView = [[UIImageView alloc] init];
        [self addSubview:imageView];
        _trousersImg = imageView;
    }
    return _trousersImg;
}

- (UIImageView *)shoesImg {
    if (!_shoesImg) {
        UIImageView *imageView = [[UIImageView alloc] init];
        [self addSubview:imageView];
        _shoesImg = imageView;
    }
    return _shoesImg;
}
@end
